<template>
  <div class="home-content">
    <div class="main-nav">
      <div class="nav-item" 
        v-for="(section, index) in mainSections" 
        :key="index"
        :class="{ active: currentSection === section.name }"
        @click="handleNavClick(section.name)"
      >{{ section.name }}</div>
    </div>

    <div v-if="currentSection === '首页'" class="sub-nav">
      <div class="nav-item" 
        v-for="(category, index) in categories" 
        :key="index"
        :class="{ active: currentCategory === category.name }"
        @click="currentCategory = category.name"
      >{{ category.name }}</div>
    </div>

    <div v-if="currentSection === '首页'">
      <!-- 删除轮播图相关代码 -->
      <div class="content-container">
        <div class="course-grid">
          <div class="course-card" 
            v-for="(course, index) in currentCourses" 
            :key="index"
            @click="handleCourseClick(course)"
          >
            <div class="course-image">
              <img :src="course.image" :alt="course.title">
            </div>
            <div class="course-info">
              <h3 class="course-title">{{ course.title }}</h3>
              <p class="instructor">{{ course.instructor }}</p>
            </div>
          </div>
        </div>
      </div>

      <div class="focus-section">
        <h2 class="focus-title">聚焦个人目标的学习体验</h2>
        <div class="path-card" @click="handlePathClick">
          <div class="path-content">
            <h3>个性化学习路径</h3>
            <p>基于你的学习目标和进度，智能推荐最适合的课程组合</p>
          </div>
        </div>
      </div>

      <div class="focus-section">
        <h2 class="focus-title">热门分类</h2>
        <div class="category-grid">
          <div class="category-card">
            <img :src="require('@/assets/icons/fenlei1.jpg')" alt="数据科学">
            <div class="category-info">
              <h3>数据科学</h3>
              <p>425 课程</p>
            </div>
          </div>
          <div class="category-card">
            <img :src="require('@/assets/icons/fenlei2.jpg')" alt="商务">
            <div class="category-info">
              <h3>商务</h3>
              <p>1095 课程</p>
            </div>
          </div>
          <div class="category-card">
            <img :src="require('@/assets/icons/fenlei3.jpg')" alt="计算机科学">
            <div class="category-info">
              <h3>计算机科学</h3>
              <p>668 课程</p>
            </div>
          </div>
          <div class="category-card">
            <img :src="require('@/assets/icons/fenlei4.jpg')" alt="健康">
            <div class="category-info">
              <h3>健康</h3>
              <p>471 课程</p>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div v-else class="content-container">
      <div class="my-learning">
        <!-- 这里可以添加"我的学习"页面的内容 -->
      </div>
    </div>
  </div>

  <!-- 添加页面底部 -->
  <footer class="footer">
    <div class="footer-content">
      <div class="footer-section">
        <h3>关于我们</h3>
        <ul>
          <li><a href="#">公司简介</a></li>
          <li><a href="#">联系我们</a></li>
          <li><a href="#">加入我们</a></li>
          <li><a href="#">帮助中心</a></li>
        </ul>
      </div>
      <div class="footer-section">
        <h3>探索</h3>
        <ul>
          <li><a href="#">解决方案</a></li>
          <li><a href="#">热门分类</a></li>
          <li><a href="#">学习路径</a></li>
          <li><a href="#">帮助和支持</a></li>
        </ul>
      </div>
      <div class="footer-section">
        <h3>法律</h3>
        <ul>
          <li><a href="#">服务条款</a></li>
          <li><a href="#">隐私政策</a></li>
          <li><a href="#">版权声明</a></li>
          <li><a href="#">免责声明</a></li>
        </ul>
      </div>
    </div>
    <div class="footer-bottom">
      <p>© 2025 学了喵 版权所有</p>
    </div>
  </footer>
</template>

<script>
export default {
  name: 'HomeContent',
  data() {
    return {
      currentSection: '首页',
      mainSections: [
        { name: '首页' },
        { name: '我的学习' }
      ],
      currentCategory: '算法',
      categories: [
        { name: '算法' },
        { name: 'Python' },
        { name: '大数据' }
      ],
      // 删除轮播图数据
      // banners: [...],
      // currentBannerIndex: 0,
      algorithmCourses: [
        {
          title: '算法设计与分析',
          instructor: '张教授',
          rating: '4.7',
          reviews: '164',
          image: require('@/assets/courses/1.jpg')
        },
        {
          title: '数据结构与算法',
          instructor: '李教授',
          rating: '4.6',
          reviews: '173',
          image: require('@/assets/courses/2.jpg')
        },
        {
          title: '大数据算法',
          instructor: '王教授',
          rating: '4.4',
          reviews: '44',
          image: require('@/assets/courses/3.jpg')
        },
        {
          title: '程序设计与算法',
          instructor: '刘教授',
          rating: '4.8',
          reviews: '19',
          image: require('@/assets/courses/4.jpg')
        }
      ],
      pythonCourses: [
        {
          title: 'Python基础教程',
          instructor: '王教授',
          rating: '4.8',
          reviews: '245',
          image: require('@/assets/courses/1.jpg')
        },
        {
          title: 'Python高级编程',
          instructor: '李教授',
          rating: '4.7',
          reviews: '189',
          image: require('@/assets/courses/2.jpg')
        },
        {
          title: 'Python数据分析',
          instructor: '张教授',
          rating: '4.6',
          reviews: '156',
          image: require('@/assets/courses/3.jpg')
        },
        {
          title: 'Python爬虫技术',
          instructor: '刘教授',
          rating: '4.5',
          reviews: '132',
          image: require('@/assets/courses/4.jpg')
        }
      ],
      bigDataCourses: [
        {
          title: '大数据处理技术',
          instructor: '张教授',
          rating: '4.7',
          reviews: '198',
          image: require('@/assets/courses/1.jpg')
        },
        {
          title: '数据仓库与挖掘',
          instructor: '王教授',
          rating: '4.6',
          reviews: '167',
          image: require('@/assets/courses/2.jpg')
        },
        {
          title: 'Hadoop生态系统',
          instructor: '李教授',
          rating: '4.5',
          reviews: '145',
          image: require('@/assets/courses/3.jpg')
        },
        {
          title: '实时流处理',
          instructor: '刘教授',
          rating: '4.8',
          reviews: '178',
          image: require('@/assets/courses/4.jpg')
        }
      ]
    }
  },
  computed: {
    currentCourses() {
      switch(this.currentCategory) {
        case '算法':
          return this.algorithmCourses;
        case 'Python':
          return this.pythonCourses;
        case '大数据':
          return this.bigDataCourses;
        default:
          return this.algorithmCourses;
      }
    }
  },
  methods: {
    handleNavClick(sectionName) {
      if (sectionName === '我的学习') {
        this.$router.push('/my-learning');
      } else {
        this.currentSection = sectionName;
      }
    },
    handlePathClick() {
      this.$router.push('/learning-path');
    },
    handleCourseClick(course) {
      this.$router.push({
        path: '/course',
        query: { 
          id: course.title  // 暂时用标题作为 id，实际应该使用真实的课程 id
        }
      });
    }
  }
}
</script>

<style scoped>
.course-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
  padding: 0;
}

.content-container {
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  min-height: 500px;
  padding: 24px;
  margin: 0 20px;
}

.course-image img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: 8px 8px 0 0;
}

.course-card {
  border: 1px solid #6d28d2;  /* 修改边框颜色为主题色 */
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s ease;
  background-color: white;
}

.course-card:hover {
  border-color: #6d28d2;
  background-color: #f8f7fa;
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(109, 40, 210, 0.15);
}

.course-info {
  padding: 12px;
  text-align: left;
}

.course-title {
  font-size: 16px;
  color: #1f2937;
  margin: 0 0 8px 0;
  font-weight: 500;
  line-height: 1.4;
}

.instructor {
  color: #6b7280;
  font-size: 14px;
  margin: 0;
}

.course-image {
  padding: 0;
  margin: 0;
  line-height: 0;
}

.home-content {
  width: 75%;
  margin-left: 12%;
  margin-right: auto;
  margin-top: 20px;
}

.sub-nav {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  padding: 0 20px;
}

.nav-item {
  padding: 8px 24px;
  background-color: white;
  border-radius: 20px;
  cursor: pointer;
  color: #666;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  font-size: 15px;
  font-weight: 500;
}

.nav-item:hover {
  background-color: #f3f4f6;
  color: #6d28d2;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.nav-item.active {
  background-color: #6d28d2;
  color: white;
  box-shadow: 0 4px 12px rgba(109, 40, 210, 0.3);
}
</style>

<style scoped>
.main-nav {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #e5e7eb;
  padding: 0 20px;
}

.main-nav .nav-item {
  padding: 12px 24px;
  background-color: transparent;
  border-radius: 0;
  cursor: pointer;
  color: #666;
  transition: all 0.3s ease;
  box-shadow: none;
  font-size: 16px;
  font-weight: 500;
  position: relative;
}

.main-nav .nav-item.active {
  background-color: transparent;
  color: #6d28d2;
  box-shadow: none;
}

.main-nav .nav-item.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #6d28d2;
}

.main-nav .nav-item:hover {
  background-color: transparent;
  color: #6d28d2;
}

.focus-section {
  margin-top: 40px;
  padding: 0 20px;
}

.focus-title {
  font-size: 28px;
  color: #6d28d2;
  margin: 40px 20px 24px;
  font-weight: 600;
}

.path-card {
  margin: 0 20px;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: all 0.3s ease;
}

.path-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.path-content {
  padding: 32px;
  text-align: left;
}

.path-content h3 {
  font-size: 20px;
  color: #1f2937;
  margin-bottom: 12px;
}

.path-content p {
  color: #6b7280;
  line-height: 1.6;
  margin: 0;
}

/* 主导航样式 */
.main-nav {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #e5e7eb;
  padding: 0 20px;
}

.main-nav .nav-item {
  padding: 12px 24px;
  background-color: transparent;
  border-radius: 0;
  cursor: pointer;
  color: #666;
  transition: all 0.3s ease;
  box-shadow: none;
  font-size: 16px;
  font-weight: 500;
  position: relative;
}

.main-nav .nav-item.active {
  background-color: transparent;
  color: #6d28d2;
  box-shadow: none;
}

.main-nav .nav-item.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #6d28d2;
}

.main-nav .nav-item:hover {
  background-color: transparent;
  color: #6d28d2;
}

.start-btn {
  padding: 12px 32px;
  background-color: #6d28d2;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.start-btn:hover {
  background-color: #5b21b6;
  transform: translateY(-2px);
}

.path-image {
  width: 300px;
  height: 200px;
  padding: 20px;
}

/* 修复样式 */
.path-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}
</style>

<style scoped>
.category-grid {
  display: flex;  /* 使用 flex 布局 */
  justify-content: space-between;  /* 两端对齐 */
  gap: 10px;  /* 保持卡片间的间距 */
  padding: 0;  /* 移除内边距 */
  margin: 0 20px;  /* 与上方内容保持相同的边距 */
}

.category-card {
  width: 220px;  /* 调整宽度以适应水平布局 */
  height: 100px;  /* 减小高度 */
  display: flex;
  flex-direction: row;  /* 改为水平布局 */
  align-items: center;
  justify-content: flex-start;  /* 左对齐内容 */
  padding: 15px;
  background: white;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.category-card img {
  width: 50px;
  height: 50px;
  object-fit: cover;
  margin-right: 15px;  /* 添加右侧间距 */
  margin-bottom: 0;  /* 移除底部间距 */
}

.category-info {
  text-align: left;  /* 左对齐文本 */
}

.category-info h3 {
  margin: 0 0 4px 0;
  font-size: 16px;
  font-weight: 500;
  color: #1f2937;
}

.category-info p {
  margin: 0;
  font-size: 14px;
  color: #6b7280;
}
</style>

<!-- 添加底部样式 -->
<style scoped>
.footer {
  background-color: #6d28d2;  /* 使用主题色作为背景 */
  color: white;
  padding: 60px 0 20px;
  margin-top: 60px;
  width: 100%;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.footer-section {
  width: 22%;
}

.footer-section h3 {
  font-size: 18px;
  margin-bottom: 20px;
  font-weight: 600;
  color: white;
}

.footer-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.footer-section ul li {
  margin-bottom: 10px;
}

.footer-section ul li a {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  transition: color 0.3s ease;
  font-size: 14px;
}

.footer-section ul li a:hover {
  color: white;
  text-decoration: underline;
}

.social-links {
  display: flex;
  gap: 15px;
}

.social-link {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  transition: color 0.3s ease;
  font-size: 14px;
}

.social-link:hover {
  color: white;
  text-decoration: underline;
}

.footer-bottom {
  text-align: center;
  padding-top: 30px;
  margin-top: 40px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
}
</style>